// pages/shippingAddress/add.js
import {
  areaList
} from '@vant/area-data';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: '',
    imgPath: "/images",
    id: '',
    btnColor: '#cacaca',
    showSelectAddress: false,

    //录入值
    name: '',
    telephone: '',
    address: '请选择省市区',
    addressDetail: '',
    isDefault: false,

    areaList,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log("options", options)

    //id
    if (options.id) {
      this.setData({
        id: options.id
      })
    }

    //图片路径
    const util = require("../../utils/util")
    this.setData({
      imgPath: util.getImgPath()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onTabbarChange(event) {
    console.log("onTabbarChange,event", event)
    this.setData({
      active: event.detail
    })
  },
  selectAddress(e) {
    this.setData({
      showSelectAddress: true
    })
  },
  /**
   * 选择地址取消
   */
  selAddrCancel() {
    this.setData({
      showSelectAddress: false
    })
  },
  /**
   * 选择地址确认
   */
  selAddrOk(e) {
    console.log("selAddrOk", e)
    const provice = e.detail.values[0].name;
    const city = (e.detail.values[1] && e.detail.values[1].name) ? e.detail.values[1].name : '';
    const county = (e.detail.values[2] && e.detail.values[2].name) ? e.detail.values[2].name : '';

    this.setData({
      showSelectAddress: false,
      "address": provice + " " + city + " " + county
    })
  },
  setDefault(e){
    console.log("setDefault",e)
    this.setData({
      isDefault:e.detail.value
    })
  },
  save() {
    console.log("this.data.name", this.data.name)
    console.log("this.data.telephone", this.data.telephone)
    console.log("this.data.address", this.data.address)
    console.log("this.data.addressDetail",this.data.addressDetail)
    console.log("this.data.isDefault",this.data.isDefault)

    wx.navigateTo({
      url: '/pages/shippingAddress/list',
    })
  }
})